package com.sample.provider.service.impl;

import com.sample.common.service.UserService;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService
public class UserServiceImpl implements UserService {
    @Override
    public String getUserInfo() {
        return "success";
    }

    @Override
    public void say(String user, StreamObserver<String> response) {
        // 处理传递过来的内容
        user += "杨胖胖";
        // 将处理结果返回
        response.onNext(user);
        // 告知服务消费者本次请求处理完成
        response.onCompleted();
    }

    @Override
    public StreamObserver<String> sayClient(StreamObserver<String> response) {
        return new StreamObserver<String>() {
            @Override
            public void onNext(String data) {
                System.out.println("收到信息:" + data);
                response.onNext("来自服务端的响应");
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onCompleted() {
                System.out.println("发送完成");
                response.onCompleted();
            }
        };
    }
}
